package com.party.mobile.biz.mall;

import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.party.common.paging.Page;
import com.party.common.utils.StringUtils;
import com.party.core.model.BaseModel;
import com.party.core.model.mall.MallGoods;
import com.party.core.model.mall.MallShoppingCartOutput;
import com.party.core.model.mall.MallStore;
import com.party.core.service.mall.IMallShoppingCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 购物车业务处理
 * Created by yifeng
 *
 * @date 2018/4/18 0018
 * @time 下午 14:17
 */
@Service
public class MallShoppingCartBizService {
    @Autowired
    private IMallShoppingCartService mallShoppingCartService;

    /**
     * 购物车失效商品
     *
     * @param memberId 用户id
     * @param page     分页参数
     * @return
     */
    public List<MallShoppingCartOutput> getBadShoppingCart(String memberId, Page page) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("memberId", memberId);
        Set<Integer> status = Sets.newHashSet();
        status.add(MallGoods.STATUS_DOWN);
        status.add(MallGoods.STATUS_SELL_OUT);
        params.put("statusList", status);
        params.put("isBad", true);
        List<MallShoppingCartOutput> mallShoppingCarts = mallShoppingCartService.newListPage(params, page);
        return mallShoppingCarts;
    }

    /**
     * 购物车有效商品
     *
     * @param memberId 用户id
     * @param page     分页参数
     * @return
     */
    public List<MallShoppingCartOutput> getGoodShoppingCart(String memberId, Page page) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("memberId", memberId);
        params.put("delFlag", BaseModel.DEL_FLAG_NORMAL);
        params.put("status", MallGoods.STATUS_UP);
        params.put("isNotBad", true);
        params.put("stock", 1);
        List<MallShoppingCartOutput> mallShoppingCarts = mallShoppingCartService.newListPage(params, page);
        return mallShoppingCarts;
    }

    public void transfromStoreName(MallStore mallStore, MallShoppingCartOutput output) {
        if (StringUtils.isEmpty(output.getDistributorId())) {
            output.setStoreId(mallStore.getId());
            output.setStoreName(mallStore.getName());
        } else {
            output.setStoreId(output.getDistributorId());
            output.setStoreName(output.getDistributorName());
        }
    }
}
